package com.zksk.portal.service.consult.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zksk.admin.api.domain.portal.vo.ConsultVo;
import com.zksk.common.core.domain.R;
import com.zksk.mbg.admin.domain.Carousel;
import com.zksk.mbg.admin.domain.Consult;
import com.zksk.mbg.admin.domain.Member;
import com.zksk.mbg.admin.mapper.CarouselMapper;
import com.zksk.mbg.admin.mapper.ConsultMapper;
import com.zksk.mbg.admin.mapper.MemberMapper;
import com.zksk.portal.service.consult.ConsultService;
import com.zksk.portal.service.finance.CarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ConsultServiceImpl extends ServiceImpl<ConsultMapper, Consult> implements ConsultService
{

    @Autowired
    private ConsultMapper consultMapper;

    @Autowired
    private MemberMapper memberMapper;

    /**
     * 新增企业咨询
     * @param consultVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R insert(ConsultVo consultVo)
    {
        Consult consult = BeanUtil.copyProperties(consultVo, Consult.class);
        consult.setId(null);
        Member member = memberMapper.selectById(consultVo.getMemberId());
        if (member.getStatus().equals(0))
        {
            //如果咨询的企业为未申请状态,咨询之后改为已咨询状态
            member.setStatus(1);
            memberMapper.updateById(member);
        }

        return R.ok("新增" + consultMapper.insert(consult) + "条记录！","新增成功！");
    }
}
